package java复习202407;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

public class c5_集合验证 {

    @Test
    public void arrayList验证(){
        ArrayList<Object> arrayList = new ArrayList<>();
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("f");
        arrayList.add("e");
        System.out.println(arrayList);
        int e = "c".compareTo("e");

        Collections.sort(arrayList, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {

                return ((String)o1).compareTo((String) o2);
            }
        });
        System.out.println(arrayList);

        arrayList.sort(new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                return ((String)o1).compareTo((String) o2);
            }
        });

        System.out.println(arrayList);

        arrayList.sort(new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                return ((String)o1).compareTo((String) o2);
            }
        });
        System.out.println(arrayList);

    }

    @Test
    public void linkedList验证(){
        LinkedList<Object> linkedList = new LinkedList<>();
        linkedList.add("a");
        linkedList.addLast("al");
        linkedList.addFirst("af");

        System.out.println(linkedList);
        System.out.println(linkedList.get(2));

        linkedList.remove(2);
        linkedList.remove();
        System.out.println(linkedList);

    }

    @Test
    public void hashSet验证(){
        HashSet<Object> hashSet = new HashSet<>();
        hashSet.add("ahello");
        hashSet.add("bhello");
    }

    @Test
    public void hashmap验证(){
        HashMap<String, String> hashMap = new HashMap<>();

        hashMap.put("1","a");

        System.out.println("迭代器循环");
        Iterator<Map.Entry<String, String>> iterator = hashMap.entrySet().iterator();
        for (;iterator.hasNext();){
            Map.Entry<String, String> next = iterator.next();
            System.out.println("key+"+next.getKey()+"=> value:"+next.getValue());
        }

        Set<String> strings = hashMap.keySet();
        System.out.println("keyset循环");
        for (String string : strings) {
            System.out.println(hashMap.get(string));
        }

        Set<Map.Entry<String, String>> entries = hashMap.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();

        }


    }

    @Test
    public void concurrentHashMap和hashTable的区别(){
        ConcurrentHashMap<Object, Object> hashMap = new ConcurrentHashMap<>();
        hashMap.put(1,1);

        Hashtable<Object, Object> hashtable = new Hashtable<>();
        hashtable.put(2,2);
    }


}
